package com.pro.control;

import com.pro.entity.JsonData;
import com.pro.entity.UserFeedback;
import com.pro.service.UserFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * auther 杨沛琪
 * createDate 2021/11/8
 */
@Controller
@RequestMapping("/UserFeedback")
public class UserFeedbackController {
    @Autowired
    private UserFeedbackService userFeedbackService;
    //获取反馈列表
    //分页查
    @RequestMapping("/getUserFeedbackTable")
    @ResponseBody
    public JsonData getUserFeedbackTable(Integer page, Integer limit, Integer gid){
        List<UserFeedback> table = userFeedbackService.getTable(page, limit, gid);
        return table!=null?JsonData.buildSuccess(table):JsonData.buildError("服务器错误");
    }

    //查询反馈.
    @RequestMapping("/queryFeedback")
    @ResponseBody
    public JsonData queryFeedback(Integer userId, Integer feedbackType, Integer feedbackClassification, String createDate){
        List<UserFeedback> userFeedbacks = userFeedbackService.queryFeedback(userId,feedbackType,feedbackClassification,createDate);
        return userFeedbacks!=null?JsonData.buildSuccess(userFeedbacks):JsonData.buildError("服务器错误");
    }

    //查询待审核
    @RequestMapping("/queryToBeReviewed")
    @ResponseBody
    public JsonData queryToBeReviewed(Integer feedbackStatus){
        List<UserFeedback> userFeedbacks = userFeedbackService.queryToBeReviewed(feedbackStatus);
        return userFeedbacks!=null?JsonData.buildSuccess(userFeedbacks):JsonData.buildError("服务器错误");
    }
    //查询待审核个数
    @RequestMapping("/getToBeReviewedNum")
    @ResponseBody
    public JsonData getToBeReviewedNum(){
        Integer toBeReviewedNum = userFeedbackService.getToBeReviewedNum();
        return  toBeReviewedNum!=0?JsonData.buildSuccess(toBeReviewedNum):JsonData.buildError("服务器错误");
    }
    //已受理
    @RequestMapping("/queryAccepted")
    @ResponseBody
    public JsonData queryAccepted(Integer feedbackStatus){
        List<UserFeedback> userFeedbacks = userFeedbackService.queryAccepted(feedbackStatus);
        return userFeedbacks!=null?JsonData.buildSuccess(userFeedbacks):JsonData.buildError("服务器错误");
    }
    //查询已受理个数
    @RequestMapping("/getAcceptedNum")
    @ResponseBody
    public JsonData getAcceptedNum(){
        Integer acceptedNum = userFeedbackService.getAcceptedNum();
        return  acceptedNum!=0?JsonData.buildSuccess(acceptedNum):JsonData.buildError("服务器错误");
    }
    //修改受理状态
    @RequestMapping("/updateAccepted")
    @ResponseBody
    public JsonData updateAccepted(Integer feedbackId){
        boolean b = userFeedbackService.updateAccepted(feedbackId);
        return b?JsonData.buildSuccess(b):JsonData.buildError("服务器错误11");
    }
    //删除
    @RequestMapping("/del")
    @ResponseBody
    public JsonData del(Integer feedbackId){
        boolean b = userFeedbackService.del(feedbackId);
        System.err.println(b);
        return b?JsonData.buildSuccess(b):JsonData.buildError("服务器错误11");
    }
}
